home *** CD-ROM | disk | FTP | other *** search
/ Alles Voor Internet / Tout Pour Internet / alles voor internet.iso / MacInternet™ / Telnet / Terminal 2.2 / Project / Sources / Scroll.c < prev    next >
Text File  |  1992-01-17  |  3KB  |  126 lines

  1. /*
  2.     Terminal 2.2
  3.     "Scroll.c"
  4. */
  5.  
  6. #ifdef THINK_C
  7. #include "MacHeaders"
  8. #endif
  9. #ifdef applec
  10. #pragma load ":(Objects):MacHeadersMPW"
  11. #pragma segment Main2
  12. #endif
  13.  
  14. #include "Text.h"
  15. #include "Main.h"
  16. #include "Scroll.h"
  17. #include "Document.h"
  18.  
  19. static WindowPtr Window;    /* Used by ScrollText(): Current window */
  20. static short Page;            /* Used by ScrollText(): Page size */
  21. static short Row;            /* Used by ScrollText(): Char height/width */
  22.  
  23. /* ----- Scroll window data -------------------------------------------- */
  24.  
  25. void Scroll(
  26.     register DocumentPeek w,
  27.     register short delta)
  28. {
  29.     RgnHandle updateRgn;
  30.  
  31.     updateRgn = NewRgn();
  32.     ScrollRect(&w->rect, 0, delta * w->height, updateRgn);
  33.     DrawDocument(w, delta);
  34.     DisposeRgn(updateRgn);
  35. }
  36.  
  37. /* ------ Scroll text within window (called by TrackControl()) --------- */
  38.  
  39. static pascal void ScrollText(
  40.     register ControlHandle ch,
  41.     register short part)
  42. {
  43.     register short delta;
  44.     register short ex;
  45.  
  46.     switch (part) {
  47.         case inUpButton:
  48.             delta = -Row;
  49.             break;
  50.         case inDownButton:
  51.             delta = Row;
  52.             break;
  53.         case inPageUp:
  54.             delta = -Page;
  55.             break;
  56.         case inPageDown:
  57.             delta = Page;
  58.             break;
  59.         default:
  60.             return;
  61.     }
  62.     SetCtlValue(ch, (ex = GetCtlValue(ch)) + delta);
  63.     if (ex -= GetCtlValue(ch))
  64.         Scroll((DocumentPeek)Window, ex);
  65. }
  66.  
  67. /* ----- Handle click in document window ------------------------------- */
  68.  
  69. void DocumentClick(
  70.     register DocumentPeek window,
  71.     register Point where,
  72.     short modifiers)
  73. {
  74. #pragma unused(modifiers)
  75.     register short part;
  76.     register short ex;
  77.     ControlHandle control;
  78.  
  79.     if ((part = FindControl(where, (WindowPtr)window, &control)) &&
  80.             window->vs == control) {
  81.         Row = 1;
  82.         Page = window->linesPage - 1;
  83.         if (part == inThumb) {
  84.             ex = GetCtlValue(control);
  85.             part = TrackControl(control, where, 0);
  86.             SetCtlValue(control, GetCtlValue(control));
  87.             if (ex -= GetCtlValue(control))
  88.                 Scroll(window, ex);
  89.         } else {
  90.             Window = (WindowPtr)window;
  91.             part = TrackControl(control, where, (ProcPtr)ScrollText);
  92.         }
  93.         return;
  94.     }
  95.     if (control == window->messOk && TrackControl(control, where, 0)) {
  96.         SetPort((GrafPtr)window);
  97.         HideControl(control);
  98.         EraseRect(&window->messRect);
  99.         window->mess[0] = 0;
  100.     } else {
  101.         /* If click in document window, then redraw it */
  102.         EraseRect(&window->rect);
  103.         DrawDocument(window, 0);
  104.     }
  105. }
  106.  
  107. /* ----- Adjust scroll bar to size of data ----------------------------- */
  108.  
  109. void AdjustScrollBar(register DocumentPeek window)
  110. {
  111.     register short a;
  112.     register short max;
  113.     register ControlHandle c;
  114.  
  115.     a = (FrontWindow() == (WindowPtr)window) ? 0 : 255;
  116.     c = window->vs;
  117.     max = window->buf.lines - window->linesPage;
  118.     if (max <= 0) {
  119.         max = 0;
  120.         HiliteControl(c, 255);
  121.     } else
  122.         HiliteControl(c, a);
  123.     (**c).contrlMax = max;
  124.     SetCtlValue(c, max);
  125. }
  126.